/*
 * Log.h
 *
 *  Created on:  May 29, 2009
 *      Author:  Zach Riggle A37627537
 *      Project: CSE410 Project 1
 */

#ifndef LOG_H_
#define LOG_H_

#include <iostream>
#include <string>
#include <sstream>
#include <time.h>
#include <ctime>

using namespace std;


/**
 * Logging class.  Provides flexible, multi-level logging through a simple
 * interface.  See the macros below.
 */
class Log {
public:
    enum Level { MUTEX, DEBUG, INFO, WARN, ERROR, CRITICAL };

    Log(Level level);
    virtual ~Log();

    Log& operator<< (const string&);
    Log& operator<< (const char*);
    Log& operator<< (const int&);
    Log& operator<< (const char&);
    Log& operator<< (const float&);
    Log& operator<< (const Log*);

    static void setLevel(Level newLevel);
    static string getLevelName(Level level);
    static string getDate();
    static string getPrefix(Level l);
    static string getPostfix(string fn, string file, int line);
    string getPrefix();
protected:

    stringstream currentLine;
    Level level;

    static Level outputLevel;
};

#define DEFAULT_LEVEL 			Log::ERROR

extern Log _mutex;
extern Log _debug;
extern Log _info;
extern Log _warn;
extern Log _error;
extern Log _critical;
extern char* stoplog;

#define log(logger,x) logger << logger.getPrefix() << x << Log::getPostfix(__PRETTY_FUNCTION__, __FILE__, __LINE__) << stoplog
#define logmutex(x)	log(_mutex,x)
#define debug(x)	log(_debug,x)
#define info(x)	log(_info,x)
#define warn(x) log(_warn,x)
#define warning(x) warn(x)
#define error(x) log(_error,x)
#define critical(x) log(_critical,x)

#endif /* LOG_H_ */
